/*
 *
 * Copyright (C) 2019 Zealcomm Inc. (https://www.zealcomm.com)
 *
*/
#ifndef IRTC_BASE_OBJC_IRTCLOGGING_H_
#define IRTC_BASE_OBJC_IRTCLOGGING_H_

#import <Foundation/Foundation.h>
#import <IRTC/IRTCMacros.h>

typedef NS_ENUM(NSInteger, IRTCLoggingSeverity) {
  IRTCLoggingSeverityVerbose,
  IRTCLoggingSeverityInfo,
  IRTCLoggingSeverityWarning,
  IRTCLoggingSeverityError,
};

// Logs the log string to the IRTC logstream for the given severity.
IRTC_OBJC_EXTERN void IRTCLogEx(IRTCLoggingSeverity severity, NSString* log_string);

// Sets the minimum severity to be logged to console.
IRTC_OBJC_EXTERN void IRTCSetMinDebugLogLevel(IRTCLoggingSeverity severity);

// Returns the filename with the path prefix removed.
IRTC_OBJC_EXTERN NSString* IRTCFileName(const char* filePath);

// Some convenience macros.

#define IRTCLogString(format, ...)                                           \
  [NSString stringWithFormat:@"(%@:%d %s): " format, IRTCFileName(__FILE__), \
                             __LINE__, __FUNCTION__, ##__VA_ARGS__]

#define IRTCLogFormat(severity, format, ...)                     \
  do {                                                          \
    NSString* log_string = IRTCLogString(format, ##__VA_ARGS__); \
    IRTCLogEx(severity, log_string);                             \
  } while (false)

#define IRTCLogVerbose(format, ...) \
  IRTCLogFormat(IRTCLoggingSeverityVerbose, format, ##__VA_ARGS__)

#define IRTCLogInfo(format, ...) \
  IRTCLogFormat(IRTCLoggingSeverityInfo, format, ##__VA_ARGS__)

#define IRTCLogWarning(format, ...) \
  IRTCLogFormat(IRTCLoggingSeverityWarning, format, ##__VA_ARGS__)

#define IRTCLogError(format, ...) \
  IRTCLogFormat(IRTCLoggingSeverityError, format, ##__VA_ARGS__)

#if !defined(NDEBUG)
#define IRTCLogDebug(format, ...) IRTCLogInfo(format, ##__VA_ARGS__)
#else
#define IRTCLogDebug(format, ...) \
  do {                           \
  } while (false)
#endif

#define IRTCLog(format, ...) IRTCLogInfo(format, ##__VA_ARGS__)

#endif // IRTC_BASE_OBJC_IRTCLOGGING_H_